package com.shanghai.shanghaielectric.UI.DilaogView;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.shanghai.shanghaielectric.MyApplication;
import com.shanghai.shanghaielectric.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by Administrator on 2017/9/2 0002.
 */

public class Dialog_Alert_Control_Command extends DialogFragment {


    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.bt_cancel)
    Button btCancel;
    @BindView(R.id.bt_certain)
    Button btCertain;

    @OnClick({R.id.bt_cancel, R.id.bt_certain})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_cancel:
                if ("FFAA".equals(commandName) | "FF55".equals(commandName) | "FF11".equals(commandName)) {
                    if (mAlert_Command_Listener != null) {
                        mAlert_Command_Listener.getBack(false, commandName);
                    }
                }else if ("FFBB".equals(commandName) | "FF55_debug".equals(commandName)) {

                    if (mAlert_debug_Listener != null) {
                        mAlert_debug_Listener.getBack(false, commandName);
                    }
                }else if ("delete_warning_data".equals(commandName)) {
                    if (mAlert_eventWarning_listener != null) {
                        mAlert_eventWarning_listener.getBack(false, "");
                    }
                }else if ("delete_operate_data".equals(commandName)) {
                    if (mAlert_Operate_listener != null) {
                        mAlert_Operate_listener.getBack(false, "");
                    }
                }else if ("resetSystem".equals(commandName)|"resetAPP".equals(commandName)) {
                    if (mAlert_resetSystem_listener != null) {
                        mAlert_resetSystem_listener.getBack(false, "");
                    }
                }

                dismiss();
                break;
            case R.id.bt_certain:
                if ("FFAA".equals(commandName) | "FF55".equals(commandName) | "FF11".equals(commandName)) {
                    if (mAlert_Command_Listener != null) {
                        mAlert_Command_Listener.getBack(true, commandName);
                    }
                }else if ("FFBB".equals(commandName) | "FF55_debug".equals(commandName)) {

                    if (mAlert_debug_Listener != null) {
                        mAlert_debug_Listener.getBack(true, commandName);
                    }
                }else if ("delete_warning_data".equals(commandName)) {
                    if (mAlert_eventWarning_listener != null) {
                        mAlert_eventWarning_listener.getBack(true, "");
                    }
                }else if ("delete_operate_data".equals(commandName)) {
                    if (mAlert_Operate_listener != null) {
                        mAlert_Operate_listener.getBack(true, "");
                    }
                }else if ("resetSystem".equals(commandName)|"resetAPP".equals(commandName)) {
                    if (mAlert_resetSystem_listener != null) {
                        mAlert_resetSystem_listener.getBack(true, "");
                    }
                }
                dismiss();
                break;
        }
    }

    public interface Alert_Command_Listener {
        void getBack(boolean isChooseCertain, String commandName);
    }

    public  Alert_Command_Listener mAlert_Command_Listener;

    public  void setAlert_Command_Listener(Alert_Command_Listener alert_command_listener) {
        mAlert_Command_Listener = alert_command_listener;
    }

    /**
     * -------debug-----弹窗-----------
     */
    public  Alert_Command_Listener mAlert_debug_Listener;

    public  void setAlert_Debug_Listener(Alert_Command_Listener alert_command_listener) {
        mAlert_debug_Listener = alert_command_listener;
    }

    /**
     * -------错误记录-----弹窗-----------
     */
    public static Alert_Command_Listener mAlert_eventWarning_listener;

    public static void setAlert_EventWarning_Listener(Alert_Command_Listener alert_eventWarning_listener) {
        mAlert_eventWarning_listener = alert_eventWarning_listener;
    }

    /**
     * -------错误记录-----弹窗-----------
     */
    public static Alert_Command_Listener mAlert_Operate_listener;

    public static void setAlert_Operate_Listener(Alert_Command_Listener alert_Operate_listener) {
        mAlert_Operate_listener = alert_Operate_listener;
    }
    /**
     * -------恢复出厂设置-----弹窗-----------
     */
    public static Alert_Command_Listener mAlert_resetSystem_listener;

    public static void setAlert_resetSystem_Listener(Alert_Command_Listener alert_resetSystem_listener) {
        mAlert_resetSystem_listener = alert_resetSystem_listener;
    }

    public Context mContext;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.m_dialog, container);
        ButterKnife.bind(this, view);

//        Toast.makeText(mContext, this.getTag().toString(), Toast.LENGTH_SHORT).show();
        initView();
        initData();
        return view;
    }

    private void initView() {
        /**
         * FFAA 启动
         * FF55 停机
         * FF11 复位
         * FFBB 调试启动
         * */
        if ("FFAA".equals(commandName)) {
            tvContent.setText("是否下发“启动”命令？");
        } else if ("FF55".equals(commandName)) {
            tvContent.setText("是否下发“停机”命令？");
        } else if ("FF11".equals(commandName)) {
            tvContent.setText("是否下发“复位”命令？");
        } else if ("FFBB".equals(commandName)) {
            tvContent.setText("是否下发“开始调试”命令？");
        } else if ("FF55_debug".equals(commandName)) {
            tvContent.setText("是否下发“停止调试”命令？");
        } else if ("delete_warning_data".equals(commandName)) {
            tvContent.setText("是否确定删除故障信息？");
        } else if ("delete_operate_data".equals(commandName)) {
            tvContent.setText("是否确定删除操作记录？");
        }else if ("resetSystem".equals(commandName)) {
            tvContent.setText("是否确定恢复出厂设置？\n（系统将重启）");
        }else if ("resetAPP".equals(commandName)) {
            tvContent.setText("是否确定重启系统？");
        }
    }

    public void setCommandName(String name) {
        this.commandName = name;
    }

    public String commandName;

    private void initData() {
        mContext = MyApplication.getContext();
    }


}
